#ifndef __NET_DOWNLOAD_H
#define __NET_DOWNLOAD_H

#ifdef __cplusplus
extern "C"{
#endif

#include "ekk_base/ekk_define.h"
	
#define DL_INTERRUPTED (-1)
#define DL_READ_CANCELLED (-2)
#define DL_TIMEOUT (-3)

#ifndef bool
#define bool char
#define true 1
#define false 0
#endif

typedef void* ND_HANDLE;
typedef void (*netdownload_transloading_notify_func)(ND_HANDLE h, int code, void*param);
typedef void (*netdownload_download_interrupted_notify_func)(ND_HANDLE h, void*param);

#if ENABLE_DOWNLOAD
    
bool netdownload_init(char* home);
void netdownload_uninit();

ND_HANDLE netdownload_open(char* url);
char * netdownload_get_url(ND_HANDLE h);

ND_HANDLE netdownload_open_with_user_data(char* url, void* p_user_data, int size);
long long netdownload_get_file_size(ND_HANDLE h);
int netdownload_get_should_block(ND_HANDLE h);

int netdownload_read(char* buff,int* plen,ND_HANDLE h);
long long netdownload_seek(long long ioffset,ND_HANDLE h);
void netdownload_close(ND_HANDLE h);

int netdownload_get_cache_size(ND_HANDLE h);
int netdownload_get_rate(ND_HANDLE h);
int netdownload_get_buffered_percents(ND_HANDLE h);
void netdownload_reset_buffered_buffer_pos();

void netdownload_io_interrupt_all(ND_HANDLE h);
void netdownload_io_interrupt_read(ND_HANDLE h);
void netdownload_io_resume_read(ND_HANDLE h);

void netdownload_do_block(ND_HANDLE h,int sec);
unsigned long long netdownload_havedownloaded_file_offset(ND_HANDLE h);
unsigned long long netdownload_havedownloaded_data_size(ND_HANDLE h);
unsigned long long netdownload_get_file_read_pos(ND_HANDLE h);
unsigned long netdownload_get_movie_bitrate(ND_HANDLE h);
int netdownload_set_real_read_size(ND_HANDLE h,int size);
bool netdownload_report_user_data(ND_HANDLE h,void* data,int sizeofcontent);
void netdownload_set_download_interrupted_callback(netdownload_download_interrupted_notify_func func, void* param);
void netdownload_set_transloading_callback(netdownload_transloading_notify_func func, void* param);
bool netdownload_is_download_finished(ND_HANDLE h);
char* netdownload_get_default_path();
	
void netdownload_enable_vod_read(ND_HANDLE h, bool enabled);
bool netdownload_is_vod_read_enabled(ND_HANDLE h);
unsigned int netdownload_get_vod_task_id(ND_HANDLE h);
    
#endif /*#if ENABLE_DOWNLOAD*/
	
#ifdef __cplusplus
}
#endif

#endif
